/*
***************************************************************************************
 * Javascript: main functions and tricks
 * Adaptive js // Mobile approach
 * Author: valerie@wephic.net
 *
***************************************************************************************
 */
jQuery(document).ready(function() {
  var banner = jQuery('.field-name-field-banner');
  var body = jQuery('body');
  var main = jQuery('#main');
  if(banner.length){
      main.prepend(banner);
      body.addClass('banner');
  }
  var carousel = jQuery('[id*="block-views-carousel-block"]');
  if(carousel.length){
      banner.remove();
      banner.removeClass('banner');
      main.prepend(carousel);
      body.addClass('carousel');
      jQuery('.views-field-field-slide-image',carousel).bind({
          'click':function(){
              window.location = jQuery(this).parents('li:first').find('.views-field-field-link-item a').attr('href');
          }
      });
  }
  jQuery('.field-collection-view .entity-field-collection-item .content').bind({
      'click':function(){
          window.location = jQuery('h2 a',jQuery(this)).attr('href');
      }
  });
  var w = jQuery(window);
  if(w.width()>=1300){
      jQuery('#block-widgets-s-socialmedia-profile-default').css({'position':'fixed','top':'13em','right':((w.width()-1200)/2 - 50)+'px'})
      w.resize(function() {
            jQuery('#block-widgets-s-socialmedia-profile-default').css({'right':((w.width()-1200)/2 - 50)+'px'})
      });
  }
  jQuery('.js .node-product-collection .field-name-field-designs .node-designer').bind({
      'click':function(){
          window.location = jQuery('h2 a',jQuery(this)).attr('href');
      }
  });
  /*menu smartphone*/
  var menu = jQuery('#block-system-main-menu');
  if(w.width()<768){
      menu.append('<div class="switcher"></div>');
      jQuery('.content',menu).hide();
  }
  jQuery('.switcher',menu).click(function(){
        jQuery(this).toggleClass('opened');
        jQuery('.content',menu).toggle();
  });
  w.resize(function(){
        if(w.width()<768){
            menu.append('<div class="switcher"></div>');
            jQuery('.content',menu).hide();
            jQuery('.switcher',menu).click(function(){
                jQuery(this).toggleClass('opened');
                jQuery('.content',menu).toggle();
            });
        }else{
            jQuery('.switcher',menu).remove();
            jQuery('.content',menu).show();
        }
  });
  /*flickr menu fixes*/
  var loc = window.location;
  if(loc.pathname.indexOf('flickr/set')>=0){
      var a= jQuery('a[href=/studio]',menu);
      var li = a.parents('li:first');
      li.attr('class','expanded active-trail');
      a.after('<ul class="menu"><li class="first last leaf active-trail"><a href="/flickr" title="">Galleries</a></li></ul>');
      var breadcrumb = jQuery('#breadcrumb a:first');
      breadcrumb.after(' &rsaquo; <a href="/studio">Studio</a> &rsaquo; <a href="/flickr">Galleries</a>');
  }
});